import { _decorator, Component, log, Node, Quat, RigidBody, RigidBody2D, v2, v3, Vec2, Vec3 } from 'cc';
import DataManager from './Base/DataManager';
const { ccclass, property } = _decorator;

@ccclass('Arrow')
export class Arrow extends Component {

    private rigidBody: RigidBody2D

    start() {
        this.rigidBody = this.node.getComponent(RigidBody2D);
    }

    update(deltaTime: number) {
        

        if(DataManager.Instance.myState.length == 0){
            this.node.destroy()
            return 
        }

        this.rigidBody.gravityScale = 0

        let weizhi = DataManager.Instance.myState.shift()

        // log("weizhi", weizhi)
        log("weizhi", DataManager.Instance.toString(weizhi.angle),DataManager.Instance.toString(weizhi.x), DataManager.Instance.toString(weizhi.y))

        
        
        //弧度转化成角度赋值给箭本身
        this.node.angle = DataManager.Instance.toString(weizhi.angle)
        this.node.setPosition(v3(DataManager.Instance.toString(weizhi.x), DataManager.Instance.toString(weizhi.y)))
        
        
        // log('当前位置：',this.node.position,'，角度：', angle)

        // if(this.node.position.x > 600){
        //     this.node.destroy()
        // }
        
    }

    
}


